/* 
* @Author: Jerry-chen
* @Date:   2014-07-10 02:08:04
* @Last Modified by:   Jerry-chen
* @Last Modified time: 2014-07-15 16:45:39
*/

                $(function(){
                     //AJAX获得类型属性
                     //值改变是发AJAX
                     // $('#type').mouseover(function() {
                     //     alert('df');
                     // });
                     // //获得cid
                   
                    $('#cate').change(function() {
                        //清除HTML代码
                        $('.shop_attr').empty();
                        $('.shop_stand').empty();
                        $('.shop_support').empty();
                         $('.shop_city').empty();
                        //获得CATEID
                         var cateid = $(this).val();
                 $.ajax({
                        url: APP + '&c=Goods&m=ajax_select_cate',
                        type: 'post',
                        dataType: 'json',
                        data: {'cateid' : cateid},
                        success:function(data){
                            //定义属性字符串
                            var attr = "";
                            //定义规格字符串
                            var stand="";
                            //定义支持字符串
                            var support="";
                            //定义声调字符串
                            var city="";
                            //循环返回的数据
                            $.each(data, function(k, v) {
                                //循环组合属性
                              
                                if(v.is_type == 0){

                                    attr +="<tr><th width='120' class='w100'>"+v.attrname+"</th><td>";
                                    attr +="<select class='select' name='attrvalue[]'>";
                                    $.each(v.attrvalue, function(i, m) {
                                        attr +="<option value='"+m+"'>"+m+"</option>";
                                    });
                                    attr +="<lect></td></tr>";
                                }
                                // //循环组合规格
                                // if(v.is_type == 1){
                                //     stand +="<tr><th width='120' class='w100'>"+v.attrname+"</th><td>";
                                //     stand +="<select class='select' name='standvalue[]'>";
                                //     $.each(v.attrvalue, function(i, m) {
                                //         stand +="<option value='"+m+"'>"+m+"</option>";
                                //     });
                                //     stand +="<lect>";
                                //     stand += "</td><td><input type='text' name='pricerange' />请以逗号号隔开</td></tr>";
                                // }
                                // if(v.is_type == 1){
                                //     stand +="<tr><th width='120' class='w100'>"+v.attrname+"</th><td>";
                                //     stand +="<select class='select' name='standvalue[]'>";
                                //     $.each(v.attrvalue, function(i, m) {
                                //         stand +="<option value='"+m+"'>"+m+"</option>";
                                //     });
                                //     stand +="<lect>";
                                //     stand += "</td><td><span class='add_stand'>"+"+增加规格"+"</span><span class='del_stand'>"+"-删除规格"+"</span></td></tr>";
                                // }
                                 //循环组合支持
                                 if(v.is_type == 2){
                                    support +="<tr><th width='120' class='w100'>"+v.attrname+"</th><td>";
                                    $.each(v.attrvalue, function(i, m) {
                                        support +="<input type='checkbox'  name='support[]' value='"+m+"'/>" + m;
                                    });
                                    support += "</td></tr>";
                                }
                                 //循环组合城市
                                if(v.is_type == 3){

                                    city +="<tr><th width='120' class='w100'>"+v.attrname+"</th><td>";
                                    city +="<select class='select' name='city'>";
                                    $.each(v.attrvalue, function(i, m) {
                                        city +="<option value='"+m+"'>"+m+"</option>";
                                    });
                                    attr +="<lect></td></tr>";
                                }
                                // alert('2');
                            });
                            
                            //追加到HTML中
                            // alert(attr);
                            $('.shop_attr').append(attr);
                            // $('.shop_stand').append(stand);
                            $('.shop_support').append(support);
                            $('.shop_city').append(city);

                            //点击增加规格
                            $('.add_stand').live('click', function() {
                                var obj = $(this).parents('tr').clone();
                                $(this).parents('tr').after(obj);
                            });

                            //点击删除规格
                            $('.del_stand').live('click',function(){
                                $(this).parents('tr').remove();
                                $(this).remove();
                            })

                    
                }
            })




                    });
                });
